package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.*;
import com.addplus.townmall.server.api.model.town.expand.StoreProductExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商城收藏表 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-08-27
 */
public interface MemberCollectMapper extends BaseAddMapper<MemberCollect> {


    @Select("SELECT sp.id,sp.shop_code,sp.shop_name,sp.shop_describe,sp.shop_imgs,sp.sale_price,sp.line_price,sp.shop_seal_img," +
            "mc.gmt_create FROM member_collect mc LEFT JOIN shop_product sp ON sp.id = mc.collect_id " +
            "WHERE mc.member_id = #{memberId} AND mc.is_delete = 0 AND sp.is_deleted = 0 ORDER BY mc.gmt_create")
    List<ShopProduct> getShopProductCollectByPage(Page page, @Param("memberId") Integer memberId);

    @Select("SELECT sp.id,sp.shop_code,sp.shop_name,sp.shop_describe,sp.shop_imgs,sp.shop_seal_img,sp.sale_price,sp.line_price," +
            "mc.gmt_create FROM member_collect mc LEFT JOIN shop_product sp ON sp.id = mc.collect_id " +
            "WHERE mc.member_id = #{memberId} AND mc.is_delete = 0 AND sp.is_deleted = 0 AND " +
            " mc.gmt_create  between date_sub(now(),interval 6 month) and now()" +
            " and  DATE_FORMAT( mc.gmt_create , '%Y%m' ) != DATE_FORMAT( CURDATE( ) , '%Y%m' )" +
            "  ORDER BY mc.gmt_create")
    List<ShopProduct> getShopProductCollectByThisHalfyear(Page page, @Param("memberId") Integer memberId);

    @Select("SELECT sp.id,sp.shop_code,sp.shop_name,sp.shop_describe,sp.shop_imgs,sp.shop_seal_img,sp.sale_price,sp.line_price," +
            "mc.gmt_create FROM member_collect mc LEFT JOIN shop_product sp ON sp.id = mc.collect_id " +
            "WHERE mc.member_id = #{memberId} AND mc.is_delete = 0 AND sp.is_deleted = 0 AND " +
            "DATE_FORMAT( mc.gmt_create , '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) ORDER BY mc.gmt_create")
    List<ShopProduct> getShopProductCollectByThisMonth(Page page, @Param("memberId") Integer memberId);

    @Select("SELECT s.id,s.store_name,s.icon_path,s.store_backage_path,s.store_introduction,mc.gmt_create FROM member_collect mc " +
            "LEFT JOIN store s ON s.id = mc.collect_id WHERE mc.member_id = #{memberId} " +
            "AND mc.is_delete = 0 AND s.is_delete = 0 ORDER BY mc.gmt_create")
    List<StoreProductExpand> getStoreCollectByPage(Page page, @Param("memberId") Integer memberId);

    @Select("SELECT s.id,s.title,s.img_thumb,s.img,s.brief,mc.gmt_create FROM member_collect mc " +
            "LEFT JOIN story_article s ON s.id = mc.collect_id WHERE mc.member_id = #{memberId} " +
            "AND mc.is_delete = 0 AND s.is_delete = 0 ORDER BY mc.gmt_create")
    List<StoryArticle> getStoryArticleByPage(Page page, @Param("memberId") Integer memberId);


    @Select("SELECT g.id,g.gift_card_name,g.gift_card_imgs,g.gitf_sale_describe,mc.gmt_create FROM " +
            "member_collect mc LEFT JOIN gift_card g ON g.id = mc.collect_id WHERE mc.member_id = #{memberId}" +
            "AND mc.is_delete = 0 AND g.is_delete = 0 ORDER BY mc.gmt_create")
    List<GiftCard> getGiftCardByPage(Page page, @Param("memberId") Integer memberId);

}
